//
//  CustomButton.m
//  GoldenWatercourse
//
//  Created by lxj on 2016/10/19.
//  Copyright © 2016年 lxj. All rights reserved.
//

#import "CustomButton.h"

@implementation CustomButton{
    UILabel *_label;
    UIView *_line;
}

-(instancetype) initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = [UIColor whiteColor];
        self.userInteractionEnabled = YES;
        
        _label = [[UILabel alloc] init];
        _label.layer.cornerRadius = 10;
        _label.layer.masksToBounds = YES;
        _label.textColor = TextDescribeColor;
        _label.font = Font_14;
        _label.backgroundColor = [UIColor clearColor];
        [self addSubview:_label];
        [_label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_top).with.offset(10);
            make.centerX.equalTo(self.mas_centerX);
            make.bottom.equalTo(self.mas_bottom).with.offset(-10);
        }];
        
        
        _line = [[UIView alloc] init];
        _line.hidden = YES;
        _line.backgroundColor = KRedColor;
        [self addSubview:_line];
    }
    return self;
}
-(void)setShowBack:(BOOL)showBack{
    _showBack = showBack;
    
    if (_customType == CustomTypeCirCle) {
        _line.hidden = YES;
        if (_showBack) {//选中
            _label.textColor = [UIColor whiteColor];
            _label.backgroundColor = KRedColor;
        }else{
            _label.textColor = TextDescribeColor;
            _label.backgroundColor = [UIColor clearColor];
        }
    }else if (_customType == CustomTypeLine){
        _label.backgroundColor = [UIColor clearColor];
        if (_showBack) {//选中
            _label.textColor = KRedColor;
            _line.hidden = NO;
        }else{
            _label.textColor = TextDescribeColor;
            _line.hidden = YES;
        }
    }else if (_customType == CustomTypeOrigion){
        _line.hidden = YES;
        _label.backgroundColor = [UIColor clearColor];
        if (_showBack) {//选中
            _label.textColor = KRedColor;
        }else{
            _label.textColor = TextDescribeColor;
        }
    }
}
-(void)setLabelText:(NSString *)labelText{
    _labelText = labelText;
    _label.text = [NSString stringWithFormat:@" %@ ",_labelText];
    CGRect rect = [_label.text boundingRectWithSize:CGSizeMake(MAXFLOAT, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:Font_14} context:nil];
    _line.frame = CGRectMake((self.width - rect.size.width) / 2, self.height - 3,rect.size.width, 3);
}
@end
